package com.pearadmin.pro.modules.stu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pearadmin.pro.modules.stu.domain.StuBusp;
import com.pearadmin.pro.modules.stu.domain.StuFollow;
import com.pearadmin.pro.modules.stu.repository.StuBuspRepository;
import com.pearadmin.pro.modules.stu.repository.StuFollowRepository;
import com.pearadmin.pro.modules.stu.service.StuFollowService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;


@Service
public class StuFollowServiceImpl extends ServiceImpl<StuFollowRepository, StuFollow> implements StuFollowService {


    @Autowired
    private StuFollowService stuFollowService;
    @Autowired
    private StuBuspRepository stuBuspRepository;


    @Override
    public boolean addStuFollow(StuFollow stuFollow) {
        stuFollowService.saveOrUpdate(stuFollow);
        if (null != stuFollow.getBuspId()&& StringUtils.isNotBlank(stuFollow.getFlwAfter())) {
            StuBusp stuBusp = stuBuspRepository.selectById(stuFollow.getBuspId());
            stuBusp.setInterDegree(stuFollow.getFlwAfter());
            stuBusp.setUpdateTime(LocalDateTime.now());
            stuBuspRepository.updateById(stuBusp);
        }
        return true;
    }
}
